package com.shujia.flink.transformation

import org.apache.flink.api.java.functions.KeySelector
import org.apache.flink.streaming.api.scala._

object Demo3KeyBy {
  def main(args: Array[String]): Unit = {

    val env: StreamExecutionEnvironment = StreamExecutionEnvironment.getExecutionEnvironment

    env.setParallelism(2)

    val ds1: DataStream[String] = env.socketTextStream("master", 9999)


    ds1
      .map((_, 1))
      .keyBy(new KeySelector[(String, Int), String] {
        override def getKey(value: (String, Int)): String = {
          value._1
        }
      })
      .sum(1)
      .print()


    env.execute()

  }
}
